package eleanor.ltd.isne.entities.pages.action;

import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.tapestry5.beaneditor.NonVisual;

import eleanor.ltd.isne.entities.action.Action;
import eleanor.ltd.isne.entities.pages.Pages;

@Entity
@Table(name = "pagesAction")
@AssociationOverrides({
	@AssociationOverride(name = "papk.action", joinColumns = @JoinColumn(name = "action_id")),
	@AssociationOverride(name = "papk.pages", joinColumns = @JoinColumn(name = "page_id")) })
public class PagesAction {
	
	@EmbeddedId
	private PagesActionPK papk = new PagesActionPK();
	
	public PagesActionPK getPapk() {
		return papk;
	}

	public void setPapk(PagesActionPK papk) {
		this.papk = papk;
	}
	
	public void setAction(Action action) {
		papk.setAction(action);
	}
	
	@Transient
	public Action getAction() {
		return papk.getAction();
	}
	
	public void setPages(Pages pages) {
		papk.setPages(pages);
	}
	
	public Pages getPages() {
		return papk.getPages();
	}
	
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		PagesAction that = (PagesAction) o;

		if (getPapk() != null ? !getPapk().equals(that.getPapk()) : that.getPapk() != null)
			return false;

		return true;
	}

}
